package com.xw.lora.vo;

import com.xw.lora.enums.ResultCodeEnum;
import lombok.Data;

import java.io.Serializable;

/**
 * xw-soil
 * 通用接口返回数据格式
 *
 * @Author : LiuZhi
 * @Date : 2020-09-05 10:10
 */
@Data
public class Result<T> implements Serializable{

    private Integer code;
    private T data;
    private String msg;

    public Result(Integer code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public Result(Integer code, T data){
        this.code = code;
        this.data = data;
    }

    public Result(Integer code , String msg, T data){
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    public static Result ok(){
        return new Result(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg());
    }

    public static Result ok(String msg){
        return new Result(ResultCodeEnum.SUCCESS.getCode(),msg);
    }

    public static Result ok(ResultCodeEnum codeEnum){
        return new Result(ResultCodeEnum.SUCCESS.getCode(),codeEnum.getMsg());
    }

    public static Result ok(ResultCodeEnum codeEnum,Object data){
        return new Result(ResultCodeEnum.SUCCESS.getCode(),codeEnum.getMsg(), data);
    }

    public static Result ok(Object data){
        return new Result(ResultCodeEnum.SUCCESS.getCode(),ResultCodeEnum.SUCCESS.getMsg(), data);
    }

    public static Result ok(String msg,Object data){
        return new Result(ResultCodeEnum.SUCCESS.getCode(), msg, data);
    }

    public static Result fail(){
        return new Result(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
    }

    public static Result fail(ResultCodeEnum codeEnum){
        return new Result(codeEnum.getCode(),codeEnum.getMsg());
    }

    public static Result fail(ResultCodeEnum codeEnum,Object data){
        return new Result(codeEnum.getCode(),codeEnum.getMsg(),data);
    }



}
